#ifndef HISTORYFRAME_H_
#define HISTORYFRAME_H_

#include <map>
#include <wx/wx.h>
#include <wx/treectrl.h>
#include "../../core/Buddy.h"
#include "../../core/events/ImppCommandEvent.h"
#include "../../core/events/MessageEvent.h"
#include "../StdUserInterfaceModule/interfaces/iChatLog.h"
#include "../../core/interfaces/iModule.h"
#include "../../core/interfaces/iUserInterface.h"

namespace Impp
{
/*
struct wxTreeItemIdCmp {
  bool operator()( const wxTreeItemId  & s1, const wxTreeItemId & s2 ) const {
	  wxLogDebug(wxT("cmp"));
    return s1 == s2;
  }
};
*/

#define STD_HISTROY_MODULE_NAME 		wxT("StdHistoryModule")
#define STD_HISTORY_MODULE_ACTION_SHOW 	wxT("showHistoryFrame")

class HistoryFrame : public wxFrame
{
private:
	enum{
		ID_TREE = wxID_HIGHEST +1
	};

	Buddy* buddy;
	wxTreeCtrl* tree;
	iChatLog* view;
	wxTreeItemId root;
	HistorySession* displayedSession;
	std::map<wxTreeItemIdValue, HistorySession*> sessions;
	static std::vector<HistoryFrame*> openedFrames;


public:
	HistoryFrame(wxWindow* win, Buddy* buddy);
	virtual ~HistoryFrame();

	static void updateOpenFrames(Buddy* buddy);

protected:
	void onSelectionChanged(wxTreeEvent & event);

private:
	void update(Buddy* buddy);
	void writeHistoryEntry(HistoryEntry* entry);
	void writeHistorySession(HistorySession* session);

private:
	DECLARE_EVENT_TABLE()

};

class StdHistoryModule : public iModule{

	DECLARE_DYNAMIC_CLASS(StdHistoryModule)

public:
	StdHistoryModule(){};
	virtual ~StdHistoryModule(){};

	void moduleInit();
	virtual void moduleDestroy();

	void onImppCommand(ImppCommandEvent & event);
	void onMessage(MessageEvent & event);
	static void wxCALLBACK addBuddyMenuItem(iMenu* menu, Buddy* buddy);

};

}

#endif /*HISTORYFRAME_H_*/
